package com.lxu.demo.endecode;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;

public class 编码解码可逆不可逆测试 {

    public static void main(String[] args) throws Exception {
        String str = "徐良"; //[-27, -66, -112, -24, -119, -81]

        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
        System.out.println(new String(bytes));
        System.out.println("-------------------");

        byte[] bytes1 = str.getBytes(Charset.defaultCharset());
        System.out.println(Arrays.toString(bytes1));
        System.out.println(new String(bytes1, Charset.defaultCharset()));
        System.out.println("-------------------");

        byte[] bytes2 = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes2));
        System.out.println(new String(bytes2, "GBK"));
        System.out.println("-------------------");

        byte[] bytes3 = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes3));
        System.out.println(new String(bytes3, "UTF-8"));
        System.out.println("-------------------");

        byte[] bytes4 = str.getBytes("GBK");
        String str4 = Arrays.toString(bytes4);
        System.out.println(str4);


        str4 = new String(bytes4,"UTF-8");
        System.out.println(str4);

        byte[] bytes5 =str4.getBytes("UTF-8");
        str4 = Arrays.toString(bytes5);
        System.out.println(str4);

        str4 = new String(bytes5,"GBK");
        System.out.println(str4);
        System.out.println("-------------------");

        byte[] bytes6 = str.getBytes("GBK");
        String str5 = Arrays.toString(bytes6);
        System.out.println(str5);


        str5 = new String(bytes6,"ISO-8859-1");
        System.out.println(str5);

        byte[] bytes7 =str5.getBytes("ISO-8859-1");
        str5 = Arrays.toString(bytes6);
        System.out.println(str5);

        str5 = new String(bytes7,"GBK");
        System.out.println(str5);

    }
}
